package com.woniuxy.service.impl;

import com.woniuxy.dao.AddressDao;
import com.woniuxy.entity.Address;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;

    @Override
    public ResponseEntity findAll() {
        List<Address> all = addressDao.findAll();
        return new ResponseEntity(200,"查询成功",all);
    }


    @Override
    public ResponseEntity findOne(int id) {
        Address address = addressDao.findOne(id);
        return new ResponseEntity<>(200,"查询成功",address);
    }


    @Override
    public ResponseEntity update(Address address) {
        int i = addressDao.update(address);
        if (i==0){
            return ResponseEntity.FAIL;
        }else {
            return ResponseEntity.SUCCESSFUL;
        }
    }

    @Override
    public ResponseEntity addOne(Address address) {
        int i = addressDao.addOne(address);
        if (i==0){
            return ResponseEntity.FAIL;
        }else {
            return ResponseEntity.SUCCESSFUL;
        }
    }


    @Override
    public ResponseEntity delete(int id) {
        int i = addressDao.delete(id);
        if (i==0){
            return ResponseEntity.FAIL;
        }else {
            return ResponseEntity.SUCCESSFUL;
        }
    }
}
